﻿#ifndef JFCAMERA_H
#define JFCAMERA_H

#include "XCloudSDK/XCloudSDK.h"
#include "XNetSDK/XNetSDKDefine.h"
#include "cameraProvider.h"
#include <QThread>
#include "QmlSignal.h"

#include "cameraItem.h"

class JFCameraItem : public CameraItem
{
    Q_OBJECT

public:
    JFCameraItem(QString name, QString ip, int port, QString usrName, QString pswd);

    void start() override;                   // 开始捕获线程
    void stop() override;                    // 停止捕获线程

    void connectCamera() override;           // 注册
    void logout() override;                  // 登出

    void setProvider(QSharedPointer<CameraImageProvider> provider) override;            // 设置该相机输出的目标provider
    void clearProvider() override;                                       // 清除目标provider

    Q_PROPERTY(bool isConnected READ getIsConnected NOTIFY sigIsConnectedChanged);          // 摄像头连接状态
    bool getIsConnected() override { return isConnected; }       // 获取当前相机的注册状态


private:
    void run() override;
//    int pMsgCallback(XSDK_HANDLE hObject, int nMsgId, int nParam1, int nParam2, int nParam3,
//                                     const char* szString, void* pObject, int64 lParam, int nSeq, void* pUserData, void* pMsg)

signals:
    void sigIsConnectedChanged();
    void sigRefresh(QString);

public slots:
    void captureImage();
    void updateCameraImage(int nParam2, void *pUserData);       // 临时，给前端调用
public:


    bool        isConnected = false;

    QString     _cameraName;        // 相机名称
    QString     _cameraIp;
    int         _cameraPort;
    QString     _cameraUsrName;
    QString     _cameraPassword;

    QSharedPointer<CameraImageProvider>   _provider = nullptr;      // 向QML前端输出图片

    QTimer*     _timer = nullptr;

    // 摄像头参数
    LONG    lUserID = -1;
    HWND    hWnd;
    LONG    lRealPlayHandle = -1;

    bool    _keepRun = false;


    QMutex  startStopMutex;
};

#endif // JFCAMERA_H
